﻿@page
@model FytSoa.Web.Pages.FytAdmin.Shop.SpectCodeModifyModel
@{
    ViewData["Title"] = "商城-规格值管理";
    Layout = "~/Pages/FytAdmin/_Layout.cshtml";
}
<div id="app">
    <form class="layui-form form-cus" action="" v-if="m">
        <div class="layui-form-item">
            <label class="layui-form-label">规格值</label>
            <div class="layui-input-block">
                <input type="text" v-model="m.code" name="code" maxlength="50" lay-verify="required" lay-verType="tips" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">排序</label>
            <div class="layui-input-block">
                <div id="sort" style="position:relative; top:16px;"></div>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit="" lay-filter="submit" id="submit"><i class="layui-icon layui-icon-loading layui-icon layui-anim layui-anim-rotate layui-anim-loop layui-hide"></i>立即提交</button>
                <button type="button" class="layui-btn layui-btn-primary btn-open-close">取消</button>
            </div>
        </div>
    </form>
</div>
@section Scripts{
    <script>
        var oc, vm = new Vue({
            el: '#app',
            data: {
                m: {}
            }
        });
        layui.config({
            base: '/themes/js/modules/'
        }).use(['layer', 'jquery', 'common', 'form', 'slider'], function () {
            var form = layui.form, $ = layui.jquery, os = layui.common, slider = layui.slider;
            vm.m.guid = os.getUrlParam('guid');            
            var sort = slider.render({
                elem: '#sort'
                , theme: '#1E9FFF'
                , input: true
                , change: function (value) {
                    vm.m.sort = value;
                }
            });
            var index = parent.layer.getFrameIndex(window.name);
            oc = {
                init() {
                    os.ajax('api/shop/spect/code/model', {parm:vm.m.guid}, function (res) {
                        if (res.statusCode === 200) {
                            vm.m = res.data;
                            sort.setValue(vm.m.sort);
                            vm.$nextTick(function () {
                                form.render();
                            });
                        } else {
                            os.error(res.message);
                        }
                    });
                }

            };
            oc.init();
            //监听提交
            form.on('submit(submit)', function (data) {
                $('#submit').attr('disabled', true).find('i').removeClass('layui-hide');
                var urls = "api/shop/spect/code/add";
                if (vm.m.guid) {
                    urls = "api/shop/spect/code/update";
                }
                vm.m.spectGuid = os.getUrlParam('spectguid'); 
                console.log(vm.m);
                os.ajax(urls, vm.m, function (res) {
                    $('#submit').attr('disabled', false).find('i').addClass('layui-hide');
                    if (res.statusCode == 200) {
                        parent.layer.close(index);
                    }
                    else {
                        os.error(res.message);
                    }
                });
                return false;
            });
            $(".btn-open-close").on('click', function () {
                parent.layer.close(index);
            });
        });
    </script>
}
